function [w, x, y, status] = roms_ksliceuv ( rslice_data, timestep, klayer )
% ROMS_ZSLICEUV:
%
% USAGE:  [w, x, y, status] = roms_ksliceuv ( rslice_data, timestep, klayer );
%
% PARAMETERS:
% Input:
%     rslice_data:  global data structure
%     timestep:  zero-based time index
%     klayer:  zero-based sigma coordinate index
% Output:
%     w:  complex velocity vector w=(u + i*v) rotated by roms angle
%     x, y:  defines the grid on which w is defined
%     status:  -1 if the routine fails
%
% USES:  roms_zslice
%
% AUTHOR:  John Evans (jevans@marine.rutgers.edu)
%

w = [];
x = [];
y = [];
status = -1;

%
% Get the u and v.  Must name them specifically.
[xu,yu,u] = roms_kslice ( rslice_data, 'u', timestep, klayer );
[xv,yv,v] = roms_kslice ( rslice_data, 'v', timestep, klayer );


x = (xu(1:end-1,:) + xu(2:end,:))/2;
y = (yu(1:end-1,:) + yu(2:end,:))/2;
u = (u(1:end-1,:) + u(2:end,:))/2;

xv = (xv(:,1:end-1) + xv(:,2:end))/2;
yv = (xv(:,1:end-1) + xv(:,2:end))/2;
v = (v(:,1:end-1,:) + v(:,2:end,:))/2;

w = u+i*v;

%
% Now apply the rotation
switch ( rslice_data.rslice_grid.coordsys )
case 'xy'
	;
case 'geographic'
	angle = rslice_data.rslice_grid.angle.data;
	
	angle = (angle(1:end-1,:) + angle(2:end,:))/2;
	angle = (angle(:,1:end-1) + angle(:,2:end))/2;
	w=w.*exp(sqrt(-1)*angle);
	

otherwise
	msg = sprintf ( '%s:  unhandled coordsys ''%s''\n', mfilename, rslice_data.rslice_grid.coordsys );
	rslice_error ( msg );
end

return
